package zut.ybt;

import java.sql.*;

public class demo {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //1. 注册驱动
        Class.forName("com.mysql.cj.jdbc.Driver");

        //2. 获取连接
        String url = "jdbc:mysql://127.0.0.1:3306/db1";
        String username = "root";
        String password = "050602";
        // Connect 1-获取执行sql的对象，2-管理事务
        Connection conn = DriverManager.getConnection(url, username, password);

        //3. 定义sql
        String sql = "UPDATE account SET money = 2000 WHERE id = 1";

        //4. 获取执行sql的对象Statement
        // Statement 1- 执行sql语句
        Statement stmt = conn.createStatement();

        //5. 执行sql
        int count = stmt.executeUpdate(sql);

        //6. 处理结果
        System.out.println(count);

        //7. 释放资源
        stmt.close();
        conn.close();
    }
}
